// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.audio.parameters;

import zombie.audio.FMODLocalParameter;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoObject;
import zombie.vehicles.BaseVehicle;

public final class ParameterVehicleRoadMaterial extends FMODLocalParameter {
    private final BaseVehicle vehicle;

    public ParameterVehicleRoadMaterial(BaseVehicle _vehicle) {
        super("VehicleRoadMaterial");
        this.vehicle = _vehicle;
    }

    @Override
    public float calculateCurrentValue() {
        if (!this.vehicle.isEngineRunning()) {
            return Float.isNaN(this.getCurrentValue()) ? 0.0F : this.getCurrentValue();
        } else {
            return (float)this.getMaterial().label;
        }
    }

    private ParameterVehicleRoadMaterial.Material getMaterial() {
        IsoGridSquare isoGridSquare = this.vehicle.getCurrentSquare();
        if (isoGridSquare == null) {
            return ParameterVehicleRoadMaterial.Material.Concrete;
        } else {
            IsoObject isoObject = this.vehicle.getCurrentSquare().getFloor();
            if (isoObject != null && isoObject.getSprite() != null && isoObject.getSprite().getName() != null) {
                String string = isoObject.getSprite().getName();
                if (string.endsWith("blends_natural_01_5")
                    || string.endsWith("blends_natural_01_6")
                    || string.endsWith("blends_natural_01_7")
                    || string.endsWith("blends_natural_01_0")) {
                    return ParameterVehicleRoadMaterial.Material.Sand;
                } else if (string.endsWith("blends_natural_01_64")
                    || string.endsWith("blends_natural_01_69")
                    || string.endsWith("blends_natural_01_70")
                    || string.endsWith("blends_natural_01_71")) {
                    return ParameterVehicleRoadMaterial.Material.Dirt;
                } else if (string.startsWith("blends_natural_01")) {
                    return ParameterVehicleRoadMaterial.Material.Grass;
                } else if (string.endsWith("blends_street_01_48")
                    || string.endsWith("blends_street_01_53")
                    || string.endsWith("blends_street_01_54")
                    || string.endsWith("blends_street_01_55")) {
                    return ParameterVehicleRoadMaterial.Material.Gravel;
                } else if (string.startsWith("floors_interior_tilesandwood_01_")) {
                    int _int = Integer.parseInt(string.replaceFirst("floors_interior_tilesandwood_01_", ""));
                    return _int > 40 && _int < 48 ? ParameterVehicleRoadMaterial.Material.Wood : ParameterVehicleRoadMaterial.Material.Concrete;
                } else if (string.startsWith("carpentry_02_")) {
                    return ParameterVehicleRoadMaterial.Material.Wood;
                } else if (string.contains("interior_carpet_")) {
                    return ParameterVehicleRoadMaterial.Material.Carpet;
                } else {
                    float _float = isoGridSquare.getPuddlesInGround();
                    return (double)_float > 0.1 ? ParameterVehicleRoadMaterial.Material.Puddle : ParameterVehicleRoadMaterial.Material.Concrete;
                }
            } else {
                return ParameterVehicleRoadMaterial.Material.Concrete;
            }
        }
    }

    static enum Material {
        Concrete(0),
        Grass(1),
        Gravel(2),
        Puddle(3),
        Snow(4),
        Wood(5),
        Carpet(6),
        Dirt(7),
        Sand(8);

        final int label;

        private Material(int int1) {
            this.label = int1;
        }
    }
}
